﻿using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Serilog;
using Serilog.Events;
using System;

namespace Syspetro.Core
{
    public static class InternalApp
    {
        /// <summary>
        /// 应用服务
        /// </summary>
        public static IServiceCollection ServiceCollection;
        /// <summary>
        /// 提供服务
        /// </summary>
        public static ServiceProvider ServicesProvider { get { return _ServicesProvider.Value; } }
        /// <summary>
        /// 全局配置选项
        /// </summary>
        public static IConfiguration Configuration;
        /// <summary>
        /// 是否启用权限认证
        /// </summary>
        public static bool IsAuth;
        /// <summary>
        /// Api路由前缀
        /// </summary>
        public static string ApiPrefix;
        /// <summary>
        /// 环境
        /// </summary>
        public static IWebHostEnvironment Env { get; set; }

        static Lazy<ServiceProvider> _ServicesProvider;
        public static void InitApp(this IServiceCollection _ServiceCollection, IConfiguration _Configuration, IWebHostEnvironment env, string _ApiPrefix = "api", bool _IsAuth = true)
        {
            Env = env;
            ServiceCollection = _ServiceCollection;
            _ServicesProvider = new Lazy<ServiceProvider>(() => ServiceCollection.BuildServiceProvider());
            Configuration = _Configuration;
            IsAuth = _IsAuth;
            ApiPrefix = _ApiPrefix;
        }
    }
}
